package com.SouthernWall_404.AgeDust.Common;

import com.SouthernWall_404.AgeDust.Common.Command.CharacterEditCommand;
import com.SouthernWall_404.AgeDust.Common.Event.AttachCapabilityEvent;
import com.SouthernWall_404.AgeDust.Common.Event.OnPlayerCloneEvent;
import com.SouthernWall_404.AgeDust.Common.Init.InitCapability;
import com.SouthernWall_404.AgeDust.Common.Event.PlayerIDEvent;
import com.SouthernWall_404.AgeDust.Common.Network.ModChannels;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
import org.spongepowered.asm.launch.MixinBootstrap;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(AgeDust.MODID)
public class AgeDust
{
    // Define mod id in a common place for everything to reference
    public static final String MODID = "age_dust";

    public AgeDust()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        if (FMLEnvironment.production) {
            MixinBootstrap.init();
        }

        MinecraftForge.EVENT_BUS.register(PlayerIDEvent.class);
        MinecraftForge.EVENT_BUS.register(AttachCapabilityEvent.class);
        MinecraftForge.EVENT_BUS.register(OnPlayerCloneEvent.class);

        modEventBus.addListener(this::registerChannel);
        modEventBus.addListener(InitCapability::onCapabilityRegister);

    }
    @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
    public static class CommandRegistry {
        @SubscribeEvent
        public static void onServerStarting(RegisterCommandsEvent event) {
            CharacterEditCommand.register(event.getDispatcher());
        }
    }

    private void registerChannel(FMLCommonSetupEvent event)
    {
        ModChannels.register();
    }


}
